﻿<Page x:Class="DTC.Pages.DrugManagementPage"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:toolkit="http://schemas.microsoft.com/wpf/2008/toolkit"
      xmlns:Converters="clr-namespace:DTC.Converters"
	  xmlns:Local="clr-namespace:DTC.Database"
      Title="DrugPrescriptionPage">
    <Page.Resources>
        <ResourceDictionary>
		
		<!-- DataTemplate fot DTCDrug-->
		<HierarchicalDataTemplate ItemsSource="{Binding StoredDrugs}"
									DataType="{x:Type Local:DTCDrug}">
			<Grid Height="45">
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="0.7*"/>
					<ColumnDefinition Width="0.3*"/>
				</Grid.ColumnDefinitions>
				<Border Margin="4,4,2,4"
									BorderBrush="{StaticResource ListBoxItemBorderBrush}"
									BorderThickness="1"
									CornerRadius="3"
									Grid.Column="0">
					<StackPanel VerticalAlignment="Center"
								HorizontalAlignment="Center">
						<TextBlock Text="Препарат:"
											Foreground="Gray"
											FontSize="10"
											HorizontalAlignment="Center"
											VerticalAlignment="Center"/>
						<TextBlock Text="{Binding Name}"
								VerticalAlignment="Center"
								HorizontalAlignment="Center"/>
					</StackPanel>
				</Border>
				<Border Margin="2,4,4,4"
									BorderBrush="{StaticResource ListBoxItemBorderBrush}"
									BorderThickness="1"
									CornerRadius="3"
									Grid.Column="1">
					<StackPanel VerticalAlignment="Center"
								HorizontalAlignment="Center">
						<TextBlock Text="Количество упаковок:"
											Foreground="Gray"
											FontSize="10"
											HorizontalAlignment="Center"
											VerticalAlignment="Center"/>
						<TextBlock Text="{Binding StoredBoxCount}" 
									VerticalAlignment="Center"
									HorizontalAlignment="Center"/>
					</StackPanel>
				</Border>
			</Grid>
		</HierarchicalDataTemplate>
		<!--DataTemplate for StoreDrug adapter class-->
		<HierarchicalDataTemplate ItemsSource="{Binding Drugs}"
								DataType="{x:Type Local:StoreDrug}">
			<Grid Height="35">
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="0.7*"/>
					<ColumnDefinition Width="0.3*"/>
				</Grid.ColumnDefinitions>
				<Border Margin="4,4,2,4"
									BorderBrush="{StaticResource ListBoxItemBorderBrush}"
									BorderThickness="1"
									CornerRadius="3"
									Grid.Column="0">
						<TextBlock Text="{Binding StoringForm}"
								VerticalAlignment="Center"
								HorizontalAlignment="Center"/>
				</Border>
				<Border Margin="2,4,4,4"
									BorderBrush="{StaticResource ListBoxItemBorderBrush}"
									BorderThickness="1"
									CornerRadius="3"
									Grid.Column="1">
						<TextBlock Text="{Binding Path=Drugs.Count}" 
									VerticalAlignment="Center"
									HorizontalAlignment="Center"/>
				</Border>
			</Grid>
		</HierarchicalDataTemplate>
		<!--DataTemplate for DTCDrugStore-->
		<HierarchicalDataTemplate DataType="{x:Type Local:DTCDrugStore}">
				<Grid Height="60" Margin="-25,0,0,0">
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="0.35*"/>
					<ColumnDefinition Width="0.35*"/>
					<ColumnDefinition Width="100"/>
					<ColumnDefinition Width="100"/>
				</Grid.ColumnDefinitions>
				<Border Margin="4,4,2,4"
									BorderBrush="{StaticResource ListBoxItemBorderBrush}"
									BorderThickness="1"
									CornerRadius="3"
									Grid.Column="0">
					<StackPanel VerticalAlignment="Center"
								HorizontalAlignment="Center">
						<TextBlock Text="Производитель:"
											Foreground="Gray"
											FontSize="10"
											HorizontalAlignment="Center"
											VerticalAlignment="Center"/>
						<TextBlock Text="{Binding Path=Manufacturer.NameManufacturer}"
								VerticalAlignment="Center"
								HorizontalAlignment="Center"/>
					</StackPanel>
				</Border>
				<Border Margin="2,4,2,4"
									BorderBrush="{StaticResource ListBoxItemBorderBrush}"
									BorderThickness="1"
									CornerRadius="3"
									Grid.Column="1">
					<StackPanel VerticalAlignment="Center"
								HorizontalAlignment="Center">
						<TextBlock Text="Форма выпуска:"
											Foreground="Gray"
											FontSize="10"
											HorizontalAlignment="Center"
											VerticalAlignment="Center"/>
						<TextBlock Text="{Binding Path=IssueForm.Name}" 
									VerticalAlignment="Center"
									HorizontalAlignment="Center"/>
					</StackPanel>
				</Border>
				<Border Margin="2,4,2,4"
									BorderBrush="{StaticResource ListBoxItemBorderBrush}"
									BorderThickness="1"
									CornerRadius="3"
									Grid.Column="2">
					<StackPanel VerticalAlignment="Center"
								HorizontalAlignment="Center">
						<TextBlock Text="Количество"
											Foreground="Gray"
											FontSize="10"
											HorizontalAlignment="Center"
											VerticalAlignment="Center"/>
						<TextBlock Text="в упаковке:"
											Foreground="Gray"
											FontSize="10"
											HorizontalAlignment="Center"
											VerticalAlignment="Center"/>
						<TextBlock Text="{Binding Path=UnitsInBox}" 
									VerticalAlignment="Center"
									HorizontalAlignment="Center"/>
					</StackPanel>
				</Border>
				<Border Margin="2,4,4,4"
									BorderBrush="{StaticResource ListBoxItemBorderBrush}"
									BorderThickness="1"
									CornerRadius="3"
									Grid.Column="3">
					<StackPanel VerticalAlignment="Center"
								HorizontalAlignment="Center">
						<TextBlock Text="Количество"
											Foreground="Gray"
											FontSize="10"
											HorizontalAlignment="Center"
											VerticalAlignment="Center"/>
						<TextBlock Text="на складе:"
											Foreground="Gray"
											FontSize="10"
											HorizontalAlignment="Center"
											VerticalAlignment="Center"/>
						<TextBlock Text="{Binding Count}" 
									VerticalAlignment="Center"
									HorizontalAlignment="Center"/>
					</StackPanel>
				</Border>
			</Grid>
		</HierarchicalDataTemplate>
		
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="../Resources/Brushes.xaml"/>
				<ResourceDictionary Source="../Resources/BorderStyles.xaml"/>
				<ResourceDictionary Source="../Resources/ButtonsStyles.xaml"/>
                <ResourceDictionary Source="../Resources/ListBoxStyles.xaml"/>
                <ResourceDictionary Source="../Resources/TextBlockStyles.xaml"/>
				<ResourceDictionary Source="../Resources/TreeViewStyles.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Page.Resources>
    <Grid Name="MainGrid" Margin="0" 
			VerticalAlignment="Stretch" 
			HorizontalAlignment="Stretch">
		<Grid.ColumnDefinitions>
			<ColumnDefinition Width="*"/>
            <ColumnDefinition Width="Auto"/>
		</Grid.ColumnDefinitions>
			<Grid Grid.Column="0" Grid.Row="0"
				Margin="20">
				<Grid.RowDefinitions>
					<RowDefinition Height="Auto"/>
					<RowDefinition Height="*"/>
				</Grid.RowDefinitions>
				<TextBlock Text="Заявки" 
						HorizontalAlignment="Center"
						FontSize="15"
						FontWeight="Bold"
						Grid.Row="0" Margin="0,5,0,0"/>
				<ListBox Name="OrdersListBox"
				 			Grid.Row="1" Margin="10,5,10,10"
							VerticalAlignment="Stretch"
                     		HorizontalContentAlignment="Stretch"
							ItemContainerStyle="{StaticResource ColorListBoxItem}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Grid Margin="10,0,0,0" Height="50" VerticalAlignment="Center">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="0.5*"/>
                                <ColumnDefinition Width="0.5*"/>
                                <ColumnDefinition Width="15"/>
                            </Grid.ColumnDefinitions>
                            <Border BorderBrush="{StaticResource ListBoxItemBorderBrush}" 
									BorderThickness="1" CornerRadius="3"
									Grid.Column="0" 
									Margin="6">
                                <StackPanel Grid.Column="0"
										Margin="4,0,4,0"
                                   			HorizontalAlignment="Center"
                                   			VerticalAlignment="Center">
                                    <TextBlock Text="Интервал времени:"
											Foreground="Gray"
											FontSize="10"
											HorizontalAlignment="Center"
											VerticalAlignment="Center"/>
                                    <WrapPanel>
                                        <TextBlock HorizontalAlignment="Center"
											VerticalAlignment="Center"
											FontSize="14">
                                        <TextBlock.Text>
                                            <Binding Path="DateFrom" Mode="OneWay">
                                                <Binding.Converter>
                                                    <Converters:DateTimeToDateConverter/>
                                                </Binding.Converter>
                                            </Binding>
                                        </TextBlock.Text>
                                        </TextBlock>
                                        <TextBlock Text=" - "/>
                                        <TextBlock HorizontalAlignment="Center"
											VerticalAlignment="Center"
											FontSize="14">
                                        <TextBlock.Text>
                                            <Binding Path="DateTo" Mode="OneWay">
                                                <Binding.Converter>
                                                    <Converters:DateTimeToDateConverter/>
                                                </Binding.Converter>
                                            </Binding>
                                        </TextBlock.Text>
                                        </TextBlock>
                                    </WrapPanel>
                                </StackPanel>
                            </Border>
                            <Border BorderBrush="{StaticResource ListBoxItemBorderBrush}" 
									BorderThickness="1" CornerRadius="3"
									Grid.Column="1" 
									Margin="6">
                                <StackPanel Grid.Column="1"
											Margin="4,0,4,0"
	                                   			HorizontalAlignment="Center"
	                                   			VerticalAlignment="Center">
                                    <TextBlock Text="Статус"
											Foreground="Gray"
											FontSize="10"
											HorizontalAlignment="Center"
											VerticalAlignment="Center"/>
                                    <TextBlock Text="{Binding PatientOrderStatuse.Status}"
                                   			HorizontalAlignment="Center"
                            	       		VerticalAlignment="Center"/>
                                </StackPanel>
                            </Border>
                            <Grid Grid.Column="5">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="0.5*"/>
                                    <RowDefinition Height="0.5*"/>
                                </Grid.RowDefinitions>
                                <Button Name="DeleteOrderButton"
									Grid.Row="1"
									Height="32"
									Width="10"
									Margin="2,0,0,0"
									Style="{StaticResource DelRecButton}"
									HorizontalAlignment="Right"
									VerticalAlignment="Bottom"
                                        Click="DeleteOrder_Click"
                                        Visibility="Collapsed"
                                    Tag="{Binding}">
                                    <Button.ToolTip>
                                        <ToolTip Style="{StaticResource DefaultToolTipStyle}"
												Height="33"
												Width="75"
												VerticalOffset="-27">
                                            <TextBlock Text="Удалить"/>
                                        </ToolTip>
                                    </Button.ToolTip>
                                </Button>
                                <Button Name="ViewOrderButton"
									Grid.Row="0"
									Height="32"
									Width="10"
									Margin="2,0,0,0"
									Style="{StaticResource ViewRecButton}"
									HorizontalAlignment="Right"
									VerticalAlignment="Top"
                                        Click="ViewOrder_Click"
                                    Tag="{Binding}">
                                    <Button.ToolTip>
                                        <ToolTip Style="{StaticResource DefaultToolTipStyle}"
												Height="33"
												Width="75"
												VerticalOffset="-27">
                                            <TextBlock Text="Изменить"/>
                                        </ToolTip>
                                    </Button.ToolTip>
                                </Button>
                            </Grid>
                        </Grid>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
				<Border Name="OrdersListBoxControlPanel"
						Grid.Row="1" Margin="11,6,0,12"
						HorizontalAlignment="Left"
						Width="35" 
						Style="{StaticResource ListBoxControlPanel}"
						CornerRadius="6,0,0,6" BorderThickness="0,0,1,0">
						<StackPanel>
							<Button Name="AddDrugToStoreButton"
                                    Height="25" Width="25"
                                    Margin="0,5,0,0"
                                    Style="{StaticResource AddRecButton}"
                                    VerticalAlignment="Top"
                                    HorizontalAlignment="Center"
                                    Click="AddDrugToStoreButton_Click"/>
						</StackPanel>
				</Border>
			</Grid>
        <Button Name="DrugDictionaryButton"
                Grid.Column="0" Grid.ColumnSpan="2"
                HorizontalAlignment="Right"
                VerticalAlignment="Top"
                Style="{StaticResource SearchButton}"
                Height="30" Width="90" Margin="10"
                Click="DrugDictionaryButton_Click"
                Content="Пепараты"/>
        <Grid Grid.Row="0" Grid.Column="1"
				    Margin="0,25,0,0"
				    VerticalAlignment="Stretch" >
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="0.1*"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
        </Grid>
        <StackPanel Margin="0,15,20,0" 
                    Grid.Row="0" Grid.Column="1"
                    VerticalAlignment="Top"
                    HorizontalAlignment="Right">
            <Button Name="OrderingOptionsButton"
				    Style="{StaticResource SearchButton}"
				    Height="17" Width="17"
                    Margin="0,20,0,0"
                    Click="OrderingOptionsButton_Click"
                    HorizontalAlignment="Right"
                    Visibility="Collapsed"/>
        </StackPanel>
    </Grid>
</Page>
